package com.permissionmanager.common;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;


/**
 * 功能：配置拦截器
 *
 */

@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        // 实现对跨域请求的拦截处理
        // 向注册表中添加一个自定义的拦截规则
        registry.addInterceptor(jwtInterceptor())
                .addPathPatterns("/**") // 拦截localhost:port下的所有请求（进行验证处理）
                .excludePathPatterns("/api/user/login","/api/user/register","/api/user/forgetPwd"); // 取消拦截
        super.addInterceptors(registry);
    }

    @Bean // 将该方法添加到应用程序的上下文中
    public JwtInterceptor jwtInterceptor(){
        return new JwtInterceptor();
    }
}